#ifndef HARMONY_GESTUREEVENTSVIEWCOMPONENTINSTANCE_H
#define HARMONY_GESTUREEVENTSVIEWCOMPONENTINSTANCE_H
/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "RNOH/arkui/StackNode.h"
#include "RNOH/generated/components/BaseGestureEventsViewComponentInstance.h"
#include <arkui/native_gesture.h>

namespace rnoh {
class GestureEventsViewComponentInstance : public BaseGestureEventsViewComponentInstance, StackNodeDelegate {
    using Super = BaseGestureEventsViewComponentInstance;

private:
    // 根容器
    StackNode m_stackNode;
    float m_fingers = 1.0f;
    std::string m_direction = "all";
    float m_minDistance = 8.0f;
    float m_minVelocity = 100.0f;
    std::string m_gestureType = "pan";
    float m_numberOfTaps = 1.0f;
    float m_minDurationMs = 500.0f;
    float m_minAngle = 0.0f;
    bool m_repeat = true;
    bool m_isMultiGesture = false;
    std::string m_multiGestureType = "";
    std::vector<std::string> m_multiGestures;
    std::string m_hoverGestureType = "";

    static void ReceiveEventStatic(ArkUI_NodeEvent *event); // 静态回调函数
    void ReceiveEvent(ArkUI_NodeEvent *event);              // 实际处理事件的成员函数
    static std::unordered_map<std::string, ArkUI_GestureRecognizer*> gestureMap;

public:
    explicit GestureEventsViewComponentInstance(Context context);

    bool GetRepeat();
    StackNode &getLocalRootArkUINode();

    void onPropsChanged(SharedConcreteProps const &props) override;
    void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override;
    void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override;

    void OnGestureCancel(ArkUI_GestureEvent *event, std::string gestureType);
    void OnGestureStart(ArkUI_GestureEvent *event, std::string gestureType);
    void OnGestureUpdate(ArkUI_GestureEvent *event, std::string gestureType);
    void OnGestureEnd(ArkUI_GestureEvent *event, std::string gestureType);
    void OnHover(bool isHover, std::string gestureType);
    std::vector<std::vector<Float>> GetFingerList(ArkUI_GestureEvent *event);
    void UpdateGestureProperties(SharedConcreteProps const &props);
    ArkUI_GestureRecognizer *CreateGestureRecognizer(ArkUI_NativeGestureAPI_1 *gestureApi);
    void SetupGestureCallbacks(
        ArkUI_NativeGestureAPI_1 *gestureApi, ArkUI_GestureRecognizer *gesture, std::string gestureType);
    ArkUI_GestureRecognizer *CreateGestureCreators(
        ArkUI_NativeGestureAPI_1* gestureApi, const std::string& multiGestures);
};
} // namespace rnoh

#endif // HARMONY_GESTUREEVENTSVIEWCOMPONENTINSTANCE_H
